import 'package:flutter/material.dart';
import 'package:flutter_juwo/common/common_index.dart';
import 'package:flutter_juwo/ui/utils/utils.dart';

import 'all.dart';

class OrderPage extends StatefulWidget {
  final int index;

  OrderPage(this.index);

  @override
  _OrderPageState createState() => _OrderPageState();
}

class _OrderPageState extends State<OrderPage>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  TabController _tabController;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: appBar(context),
      body: new TabBarView(
        controller: _tabController,
        children: <Widget>[
          OrderAll(),
          OrderAll(index: 1),
          OrderAll(index: 2),
          OrderAll(index: 3),
          OrderAll(index: 4),
        ],
      ),
    );
  }

  Widget appBar(BuildContext context) {
    return AppBar(
      title: Text(
        '我的任务',
        style: TextStyle(
            fontSize: ScreenUtil().setSp(34),
            fontFamily: Font.PingFangBlod,
            color: Colours.appC1),
      ),
      centerTitle: true,
      elevation: 0.0,
      brightness: Brightness.light,
      bottom: new TabBar(
        indicatorColor: Color(0xFFdf3033),
        indicatorWeight: ScreenUtil().setWidth(4),
        indicatorPadding: EdgeInsets.fromLTRB(18, 0, 18, 0),
        labelPadding: EdgeInsets.only(bottom: 0),
        unselectedLabelColor: Colours.appC1,
        labelColor: Color(0xFFE3393C),
        tabs: <Widget>[
          Tab(text: "全部"),
          Tab(text: "进行中"),
          Tab(text: "待评价"),
          Tab(text: "已完成"),
          Tab(text: "已失败"),
        ],
        controller: _tabController,
      ),
      leading: InkWell(
          highlightColor: Color(0xFFB3E5FC),
          onTap: () {
            Navigator.pop(context);
          },
          child: Container(
            padding: EdgeInsets.fromLTRB(12.0, 0.0, 12.0, 0.0),
            child: Image.asset(
              Utils.getImgPath('return_left'),
              width: 18.0,
              height: 20.0,
            ),
          )),
    );
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = new TabController(vsync: this, length: 5,initialIndex: widget.index);
  }
}
